package com.autism.day04;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

//计算一个人出生了多少天
public class DateDemo {
    public static void main(String[] args) throws ParseException {
        //获取出生日期
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入您的出生日期，格式yyyy-MM-dd");

        String birthdayDateString = scanner.next();

        //把日期字符串转为date格式
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date birthdayDate = simpleDateFormat.parse(birthdayDateString);

        //把date 转为毫秒值
        long birthdayDateTime = birthdayDate.getTime();

        //获取当前日期的毫秒值
        long todayTime = new Date().getTime();

        //计算毫秒值
        long time = todayTime - birthdayDateTime;

        System.out.println(time / 1000 / 60 / 60 / 24);

    }
}
